﻿using System.Windows.Controls;

using Game.Level;

namespace Game.Editor
{
    public class CampainTreeLevelItem : TreeViewItem
    {
        readonly CampainTreeLevelsItem _Root;
        readonly GameLevel _GameLevel;

        public CampainTreeLevelItem(CampainTreeLevelsItem root,
                                    GameLevel gameLevel)
        {
            _Root = root;
            _GameLevel = gameLevel;
            Header = "Level " + GameLevels.GetIndex(_GameLevel);
            _Root.GameLevels.Events.LevelUpdated += delegate
            {
                Header = "Level " + GameLevels.GetIndex(_GameLevel);
            };

            Init();
        }

        public GameLevel GameLevel
        {
            get { return _GameLevel; }
        }

        void Init()
        {
            _GameLevel.Milestones.MilestoneAdded += delegate(object source, MilestoneEventArgs args)
            {
                var item = new CampainTreeMilestoneItem(
                    this, args.GameMilestone);
                Items.Add(item);
            };
        }

        public void Remove()
        {
            _Root.GameLevels.Remove(_GameLevel);
            _Root.Items.Remove(this);
        }

    }
}
